package com.tomorrowbbs.service.impl;

import java.util.*;

import com.tomorrowbbs.domain.query.ForumBoardQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tomorrowbbs.mapper.ForumBoardMapper;
import com.tomorrowbbs.domain.ForumBoard;
import com.tomorrowbbs.service.IForumBoardService;

/**
 * 文章板块信息Service业务层处理
 * 
 * @author zjz
 * @date 2024-11-09
 */
@Service
public class ForumBoardServiceImpl implements IForumBoardService 
{
    @Autowired
    private ForumBoardMapper forumBoardMapper;

    /**
     * 查询文章板块信息
     * 
     * @param boardId 文章板块信息主键
     * @return 文章板块信息
     */
    @Override
    public ForumBoard selectForumBoardByBoardId(Long boardId)
    {
        return forumBoardMapper.selectForumBoardByBoardId(boardId);
    }

    /**
     * 查询文章板块信息列表
     * 
     * @param forumBoard 文章板块信息
     * @return 文章板块信息
     */
    @Override
    public List<ForumBoard> selectForumBoardList(ForumBoard forumBoard)
    {
        return forumBoardMapper.selectForumBoardList(forumBoard);
    }

    /**
     * 新增文章板块信息
     * 
     * @param forumBoard 文章板块信息
     * @return 结果
     */
    @Override
    public int insertForumBoard(ForumBoard forumBoard)
    {
        return forumBoardMapper.insertForumBoard(forumBoard);
    }

    /**
     * 修改文章板块信息
     * 
     * @param forumBoard 文章板块信息
     * @return 结果
     */
    @Override
    public int updateForumBoard(ForumBoard forumBoard)
    {
        return forumBoardMapper.updateForumBoard(forumBoard);
    }

    /**
     * 批量删除文章板块信息
     * 
     * @param boardIds 需要删除的文章板块信息主键
     * @return 结果
     */
    @Override
    public int deleteForumBoardByBoardIds(Long[] boardIds)
    {
        return forumBoardMapper.deleteForumBoardByBoardIds(boardIds);
    }

    /**
     * 删除文章板块信息信息
     * 
     * @param boardId 文章板块信息主键
     * @return 结果
     */
    @Override
    public int deleteForumBoardByBoardId(Long boardId)
    {
        return forumBoardMapper.deleteForumBoardByBoardId(boardId);
    }

    @Override
    public List<ForumBoard> getBoardTree(Integer postType) {
//        ForumBoard board= new ForumBoard();
//        board.setSort(1l);
//        board.setPostType(postType);
        List<ForumBoard> forumBoards = forumBoardMapper.selectAllForumBoardList();
        System.out.println("forumBoards : "+forumBoards);
        return convertLine2tree(forumBoards,0L);

    }
    //将查询出的forumBoards列表转化为树形结构
    private List<ForumBoard> convertLine2tree(List<ForumBoard> dataList,Long pid){
        List<ForumBoard> children = new ArrayList<>();
        for (ForumBoard forumBoard : dataList){
            if (forumBoard.getpBoardId().equals(pid)){
                forumBoard.setChildren(convertLine2tree(dataList,forumBoard.getBoardId()));
                children.add(forumBoard);
            }
        }
        Map<String, Integer> m = new HashMap<>();
        return children;

    }










}










